<?php
/**
 * Created by PhpStorm.
 * User: skytop
 * Date: 2016/7/19
 * Time: 19:32
 */

namespace Admin\Model;


use Think\Verify;

class Captcha
{
    //定义常量
    //注册验证码
    const REGISTER_CAPTCHA=1;
    //登录验证码
    const LOGIN_CAPTCHA=2;

    //创建验证码
    public static function createCaptcha($identify=self::REGISTER_CAPTCHA){
        //对验证码进行设置
        $config=array(
            'length'=>C('captcha_length'),
            'useCurve'=>C('useCurve'),
            'useNoise'=>C('useNoise')
        );


        $verify=new Verify($config);

        //生成验证码
        $verify->entry($identify);
    }

    /**
     * @param $captcha  用户输入的验证码
     * @param int $identify
     * @return bool
     */
    //校验验证码
    public static function checkCaptcha($captcha,$identify=self::REGISTER_CAPTCHA){
        $verify=new Verify();
        return $verify->check($captcha,$identify);
    }
}